package com.zzyl.nursing.controller.member;


import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.TimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class MemberReservationController extends BaseController {
    @Autowired
    private IReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
       Long userId = UserThreadLocal.getUserId();
        System.out.println("------" + userId);
         int count= reservationService.getCancelledReservationCount(userId);
        return R.ok(count);
    }




    /**
     * 新增预约信息
     */
    @PostMapping
    @ApiOperation(value = "新增预约信息")
    public AjaxResult addReservation(@RequestBody  ReservationDto reservationDto) {

            reservationService.addReservation(reservationDto);
        return AjaxResult.success();
    }
    @GetMapping("/page")
    @ApiOperation(value = "获取预约信息列表")
    public R list(Integer status,Integer pageSize,Integer pageNum) {
        List<Reservation> list= reservationService.selectMemberReservationList(status,pageSize,pageNum);
        return  R.ok(getDataTable(list))  ;
    }
   @PutMapping("/{id}/cancel")
    @ApiOperation(value = "取消预约")
    public R cancel(@PathVariable("id") Long id) {
        reservationService.UpdateReservationById(id);
        return R.ok();
    }

    /**
     * 查询每个时间段剩余的预约数量
     *
     */
    @GetMapping("/countByTime")
    @ApiOperation(value = "查询每个时间段剩余的预约数量")
    public R<List<TimeVo>> getRemainCount(Long time) {

      List <TimeVo> timeVo =reservationService.selectRemainCount(time);

         //return R.ok(reservationService.selectRemainCount(time));
        return R.ok(timeVo);
    }
}
